﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <title>我的钱包</title>
    <link rel="stylesheet" href="css/style.css?v=1.11">
    <link rel="stylesheet" href="css/index.css?v=1.11">
    <script src="/js/jquery-1.8.3.min.js?v=1.11"></script>
    <script src="/js/flexible.js?v=1.11"></script>
    <script src="/layer-mobile/layer.js?v=1.11"></script>
</head>
	<body>
		<header id="header">
			<div class="back" onclick="closeWin();">
				<img src="image/back.png">
			</div>
			<div class="title">我的钱包</div>
			<div class="btn-add"><input type="button" value="添加" id="btn-add" /></div>
		</header>
		<div class="wallet">
            <div class="wall-list">

            </div>
		</div>
		<div class="add-wallet">
			<div class="wallet-box">
				<h3>请添加真实有效钱包地址</h3>
				<div class="add-tag">
					<input type="text" class="tagBtn" id="wallettag"  placeholder="添加标签"/>
					<input type="text"  class="tagBtn" id="walletaddress" placeholder="请输入钱包地址"/>
				</div>
				<div class="ensure">
					<input type="button" value="确定"  class="ensure-btn"/>
				</div>
			</div>
		</div>
	</body>
</html>
<script type="text/javascript">
   
    var userid = getUserId(),
		res = '';
	$('#btn-add').on('click',function(){
		
		$('.add-wallet').show();
    });
    $('.add-wallet').on('click',function (event) {
       
        if (event.target.parentNode.className != 'wallet-box' && event.target.parentNode.parentNode.className != 'wallet-box') {
            $(this).hide();  
        }
         
    })
	$ajax(
		url+'getMyWalletsList.ashx',
		'get',
		{userid:userid},
		function(data){
			var wallt = data.data.walletsList; //钱包列表
			
            if (wallt.length > 0) {
                for (var i = 0, iL = wallt.length; i < iL; i++) {

                    res += '<div class="wall-item">' +
                        '<div class="operate clearfix">' +
                        '<span class="tag fl">' + wallt[i].tag + '</span>' +

                        '<span class="btn-del fr" data-id="' + wallt[i].id + '"></span>' +
                        '</div>' +
                        '<p class="wall-adress">钱包地址：<span>' + wallt[i].walletAddress + '</span></p>' +
                        '<p class="wall-time">绑定时间：' + wallt[i].createdDateTime + '</p>' +
                        '</div>';
                }
                $('.wall-list').html(res);

            } 
			
		},
		function(data){

            loginRes();
		}
    )

    $(document).ready(function () {
        $(".add-wallet .ensure-btn").click(function () {
            var myUserID = getUserId();

            $.ajax({
                type: "POST",
                url: "/API/AjaxHandler.ashx?Action=KongtouWeb.UserWalletsAjax.AddWallet",
                data: {
                    userId: myUserID,
                    tag: $("#wallettag").val(),
                    walletAddress: $("#walletaddress").val()
                },
                async: false,
                error: function (request) {
                    
                    layer.open({
                        content: '系统异常',
                        skin: 'msg',
                        time: 2
                    });
                },
                success: function (data) {
                    if (data.status == "1") {

                        layer.open({
                            content: '钱包添加成功',
                            btn: ['确定'],
                            yes: function (index) {
                                location.replace(location.href);
                            }
                        });
                    }
                    else {
                        layer.open({
                            content: data.message,
                            btn: ['确定'],
                            yes: function (index) {
                                layer.close(index);
                            }
                        });

                    }

                }
            });

        })


        $(".wall-item .btn-del").live("click",function () {
            var tagName = $(this).siblings(".tag").text();
            var myUserID = getUserId();
            var myWalletId = $(this).attr("data-id");
            
            layer.open({
                content: '确定要删除【'+ tagName+'】钱包吗？',
                btn: ['确定','取消'],
                yes: function (index)
                {
                    $.ajax({
                        type: "POST",
                        url: "/API/AjaxHandler.ashx?Action=KongtouWeb.UserWalletsAjax.RemoveWallet",
                        data: {
                            userId: myUserID,
                            walletId: myWalletId
                        },
                        async: false,
                        error: function (request) {
                            
                            layer.open({
                                content: '系统异常',
                                skin: 'msg',
                                time: 2
                            });
                        },
                        success: function (data) {
                            if (data.status == "1") {
                                location.replace(location.href);
                            }
                            else {
                                layer.open({
                                    content: data.message,
                                    skin: 'msg',
                                    time: 2
                                });
                            }

                        }
                    });
                    
                },
                no: function (index) {
                    
                }
            });


        })

        
    });

    
</script>